package com.tuanzi.loan.business.service.family.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.retry.RetryException;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.tuanzi.loan.core.aspect.Debug;

import com.tuanzi.loan.business.service.family.DistributionRecordService;
import com.tuanzi.loan.vo.request.distribution.DistributionRecordSearchRequest;
import com.tuanzi.loan.vo.response.distribution.GalaxyCardDistributionRecordSearchResponse;
import com.tuanzi.loan.business.repository.distribution.DistributionRecordRepository;
import com.tuanzi.loan.core.vo.PageSearcher;
import org.springframework.data.domain.Page;

import java.util.Map;
import java.util.Objects;

/**
 * 邀请明细统计 ServiceImplement
 * @author JinRuiyang 2018/2/7 17:45:58
 */
@Debug
@Service
@Transactional
@Retryable(value = { RetryException.class })
public class DistributionRecordServiceImpl implements DistributionRecordService {

    @Autowired
    private DistributionRecordRepository distributionrecordRepository;

    @Override
    public Map<String, Integer> getProductList() {
        return distributionrecordRepository.getProductList();
    }

    @Override
    public Map<String, Integer> getChannelList() {
        return distributionrecordRepository.getChannelList();
    }

    @Override
    public Map<String, String> getPlatformList() {
        return distributionrecordRepository.getPlatformList();
    }

    @Override
    public Map<String, Long> getDistributionActivity() {
        return distributionrecordRepository.getDistributionActivity();
    }

    /**
     * DistributionRecord查询
     * @param pageSearcher 请求信息
     * @return 响应列表
     */
    public Page<GalaxyCardDistributionRecordSearchResponse> list(PageSearcher<DistributionRecordSearchRequest> pageSearcher) {
        if (Objects.isNull(pageSearcher))
            throw new NullPointerException("pageSearcher is null");
        if (Objects.isNull(pageSearcher.getSearchCondition()) || Objects.isNull(pageSearcher.getPageable()))
            throw new NullPointerException("distributionrecordSearchRequest or pageable is null");
        return distributionrecordRepository.list(pageSearcher.getSearchCondition(),pageSearcher.getPageable());
    }
}